package org.sanguine.tests.protei.springapp.mvc.models;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.sanguine.tests.protei.springapp.mvc.models.annotations.Primary;

import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.math.BigDecimal;

/**
 * Created by alex on 25.02.14.
 * Author: Alex Kuznetsov
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class Goods implements Entity {

    private Long id;

    @Size(min = 1)
    @Pattern(regexp = "^\\D.*")
    private String title;
    @DecimalMin("0.00")
    private BigDecimal price;

    public Goods(long id, String title, BigDecimal price) {
        this.id = id;
        this.title = title;
        this.price = price;
    }

    public Goods() {
        id = 0L;
        title = "";
        price = BigDecimal.ZERO;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    @Primary
    @Override
    public String getId() {
        return id.toString();
    }

    @Primary
    @Override
    public void setId(String id) {
        this.id = new Long(id);
    }

    @Override
    public String toString() {
        return "Goods{" +
                "id=" + id +
                ", title='" + title + '\'' +
                ", price=" + price +
                '}';
    }
}
